package com.manager.core.ad.mediation;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import com.bykv.vk.openvk.TTRdVideoObject;
import com.bykv.vk.openvk.TTVfConstant;
import com.bykv.vk.openvk.TTVfNative;
import com.bykv.vk.openvk.TTVfSdk;
import com.bykv.vk.openvk.VfSlot;
import com.bykv.vk.openvk.mediation.MediationConstant;
import com.bykv.vk.openvk.mediation.ad.MediationAdSlot;
import yyee.llee.mmee.base_api_factory.ModuleConfig;
import yyee.llee.mmee.base_api_net.base_api_bean.NAdError;
import com.manager.core.ad.action.AdActionListener;
import com.manager.core.ad.bean.NAdBeanCreator;
import com.manager.core.pl190.host668.JWAdBase;
import com.manager.core.pl190.host668.NConst;

public class JWRewardAd extends JWAdBase {

    public static String TAG = ModuleConfig.AD_LOG_TAG + "_MediationRewardAd";

    // 插全屏广告对象
    private TTRdVideoObject mTTRewardVideoAd;

    // 广告展示监听器
    private TTRdVideoObject.RdVrInteractionListener mRewardVideoAdInteractionListener;

    public JWRewardAd(String placementId) {
        super(placementId);
    }

    @Override
    public void show(Activity appCompatActivity, AdActionListener adActionListener) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
        for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
            int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
            int asjkdhjaksd;
            for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
            }
            akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
        }
        super.show(appCompatActivity, adActionListener);
        if (isReady()) {
            if (mTTRewardVideoAd == null) {
                Log.d(TAG, "请先加载广告或等待广告加载完毕后再调用show方法");
                return;
            }
            /**
             * 5、设置展示监听器，展示广告
             */
            mTTRewardVideoAd.setRdVrInteractionListener(mRewardVideoAdInteractionListener = new TTRdVideoObject.RdVrInteractionListener() {

                @Override
                public void onShow() {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
                    for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
                        int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
                        int asjkdhjaksd;
                        for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                            akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
                        }
                        akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
                    }
                    Log.d(TAG, "reward show");
                }

                @Override
                public void onVideoBarClick() {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] quiwyieqasdad = new int[] { 12, 34, 3 };
                    int asdjasdhjkah;
                    // 第一层循环:表明比较的次数, 比如 length 个元素,比较次数为 length-1 次（肯定不需和自己比）
                    for (int ahjdgajhsd = 0; ahjdgajhsd < quiwyieqasdad.length - 1; ahjdgajhsd++) {
                        for (int uiqwyeuiqwe = quiwyieqasdad.length - 1; uiqwyeuiqwe > ahjdgajhsd; uiqwyeuiqwe--) {
                            if (quiwyieqasdad[uiqwyeuiqwe] < quiwyieqasdad[uiqwyeuiqwe - 1]) {
                                asdjasdhjkah = quiwyieqasdad[uiqwyeuiqwe];
                                quiwyieqasdad[uiqwyeuiqwe] = quiwyieqasdad[uiqwyeuiqwe - 1];
                                quiwyieqasdad[uiqwyeuiqwe - 1] = asdjasdhjkah;
                            }
                        }
                    }
                    Log.d(TAG, "reward click");
                }

                @Override
                public void onClose() {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] zmxcbzc = new int[] { 2, 12, 34 };
                    for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
                        int miniPost = jkashdkas;
                        for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                            if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                                miniPost = zmasdadasd;
                            }
                        }
                        if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                            int asdadavavaqvq;
                            asdadavavaqvq = zmxcbzc[jkashdkas];
                            zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                            zmxcbzc[miniPost] = asdadavavaqvq;
                        }
                    }
                    Log.d(TAG, "reward close");
                }

                @Override
                public void onVideoComplete() {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] zmxcbzc = new int[] { 2, 12, 34 };
                    for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
                        int miniPost = jkashdkas;
                        for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                            if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                                miniPost = zmasdadasd;
                            }
                        }
                        if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                            int asdadavavaqvq;
                            asdadavavaqvq = zmxcbzc[jkashdkas];
                            zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                            zmxcbzc[miniPost] = asdadavavaqvq;
                        }
                    }
                    Log.d(TAG, "reward onVideoComplete");
                }

                @Override
                public void onVideoError() {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] hajsdhjasd = new int[] { 123, 234, 45 };
                    for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
                        int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
                        int hjkhkhlhkjkad;
                        for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                            hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
                        }
                        hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
                    }
                    Log.d(TAG, "reward onVideoError");
                }

                @Override
                public void onRdVerify(boolean b, int i, String s, int i1, String s1) {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] zmxcbzc = new int[] { 2, 12, 34 };
                    for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
                        int miniPost = jkashdkas;
                        for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                            if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                                miniPost = zmasdadasd;
                            }
                        }
                        if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                            int asdadavavaqvq;
                            asdadavavaqvq = zmxcbzc[jkashdkas];
                            zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                            zmxcbzc[miniPost] = asdadavavaqvq;
                        }
                    }
                    Log.d(TAG, "reward onRewardVerify");
                }

                @Override
                public void onRewardArrived(boolean isRewardValid, int rewardType, Bundle extraInfo) {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] hajsdhjasd = new int[] { 123, 234, 45 };
                    for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
                        int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
                        int hjkhkhlhkjkad;
                        for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                            hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
                        }
                        hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
                    }
                    Log.d(TAG, "reward onRewardArrived");
                }

                @Override
                public void onSkippedVideo() {
                    int passwordfdare32432qresafdsagda32 = 123456;
                    int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
                    for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
                        int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
                        int asjkdhjaksd;
                        for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                            akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
                        }
                        akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
                    }
                    Log.d(TAG, "reward onSkippedVideo");
                }
            });
            mTTRewardVideoAd.showRdVideoVr(appCompatActivity);
            if (mAdStatus == null)
                return;
            mAdStatus.setReady(false);
        }
    }

    @Override
    protected void load(Context context) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] zmxcbzc = new int[] { 2, 12, 34 };
        for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
            int miniPost = jkashdkas;
            for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                    miniPost = zmasdadasd;
                }
            }
            if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                int asdadavavaqvq;
                asdadavavaqvq = zmxcbzc[jkashdkas];
                zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                zmxcbzc[miniPost] = asdadavavaqvq;
            }
        }
        if (!(context instanceof Activity)) {
            callLoadFail(new NAdError("-1", "context not is activtiy", "1", "cancel"));
            return;
        }
        VfSlot adslot = // "聚合广告位ID"
        new VfSlot.Builder().setCodeId(// 横竖屏设置
        getPlacementId()).setOrientation(TTVfConstant.VERTICAL).setMediationAdSlot(// 服务端奖励验证透传参数
        new MediationAdSlot.Builder().setExtraObject(// 服务端奖励验证透传参数
        MediationConstant.ADN_PANGLE, "pangleRewardCustomData").setExtraObject(MediationConstant.ADN_GDT, "gdtRewardCustomData").setExtraObject(MediationConstant.ADN_BAIDU, "baiduRewardCustomData").build()).build();
        // 需要传activity，切记！！！
        TTVfNative adNativeLoader = TTVfSdk.getVfManager().createVfNative(context);
        adNativeLoader.loadRdVideoVr(adslot, new TTVfNative.RdVideoVfListener() {

            @Override
            public void onError(int i, String s) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] quiwyieqasdad = new int[] { 12, 34, 3 };
                int asdjasdhjkah;
                // 第一层循环:表明比较的次数, 比如 length 个元素,比较次数为 length-1 次（肯定不需和自己比）
                for (int ahjdgajhsd = 0; ahjdgajhsd < quiwyieqasdad.length - 1; ahjdgajhsd++) {
                    for (int uiqwyeuiqwe = quiwyieqasdad.length - 1; uiqwyeuiqwe > ahjdgajhsd; uiqwyeuiqwe--) {
                        if (quiwyieqasdad[uiqwyeuiqwe] < quiwyieqasdad[uiqwyeuiqwe - 1]) {
                            asdjasdhjkah = quiwyieqasdad[uiqwyeuiqwe];
                            quiwyieqasdad[uiqwyeuiqwe] = quiwyieqasdad[uiqwyeuiqwe - 1];
                            quiwyieqasdad[uiqwyeuiqwe - 1] = asdjasdhjkah;
                        }
                    }
                }
                mAdStatus.setReady(false);
                callLoadFail(NAdBeanCreator.createAdError(i, s));
            }

            @Override
            public void onRdVideoVrLoad(TTRdVideoObject ttRewardVideoAd) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] hajsdhjasd = new int[] { 123, 234, 45 };
                for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
                    int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
                    int hjkhkhlhkjkad;
                    for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                        hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
                    }
                    hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
                }
                // 加载完成的回调
                mTTRewardVideoAd = ttRewardVideoAd;
                mAdStatus.setReady(true);
                callLoadSuccess();
            }

            @Override
            public void onRdVideoCached() {
            }

            @Override
            public void onRdVideoCached(TTRdVideoObject ttRewardVideoAd) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
                for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
                    int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
                    int asjkdhjaksd;
                    for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                        akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
                    }
                    akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
                }
                // 广告视频本地加载完成的回调
                mTTRewardVideoAd = ttRewardVideoAd;
            }
        });
    }

    @Override
    public boolean isReady() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
        for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
            int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
            int asjkdhjaksd;
            for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
            }
            akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
        }
        return mTTRewardVideoAd != null && mAdStatus.isReady();
    }

    @Override
    protected int getType() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] zmxcbzc = new int[] { 2, 12, 34 };
        for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
            int miniPost = jkashdkas;
            for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                    miniPost = zmasdadasd;
                }
            }
            if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                int asdadavavaqvq;
                asdadavavaqvq = zmxcbzc[jkashdkas];
                zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                zmxcbzc[miniPost] = asdadavavaqvq;
            }
        }
        return NConst.REWORD;
    }

    @Override
    public boolean isSelfBiding() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] zmxcbzc = new int[] { 2, 12, 34 };
        for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
            int miniPost = jkashdkas;
            for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                    miniPost = zmasdadasd;
                }
            }
            if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                int asdadavavaqvq;
                asdadavavaqvq = zmxcbzc[jkashdkas];
                zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                zmxcbzc[miniPost] = asdadavavaqvq;
            }
        }
        return true;
    }
}
